{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0a21cccc",
   "metadata": {},
   "source": [
    "# 一. Python知识点： [实现条件循环与判断]\n",
    "\n",
    "* 本周主要内容：if else 、for循环、range方法、注释、用户输入\n",
    "* 上周主要内容：两种python常见的IDE的安装教程及使用场景，奇数项目体验\n",
    "<br/>\n",
    "\n",
    "##  1.jupyter notebook 扩展介绍\n",
    "\n",
    "* 使用目录，让工作更加便捷     \n",
    "* jupyter 的快捷使用     \n",
    "\n",
    "\n",
    "<font color=pink size=6> jupyter notebook键盘快捷键</font>\n",
    "___\n",
    "\n",
    "### ①.进入命令模式之后（此时你没有活跃单元），我们可以尝试以下快捷键：\n",
    "\n",
    "* A 会在活跃单元之上插入一个新的单元，B 会在活跃单元之下插入一个新单元。\n",
    "* 连续按两次 D，可以删除一个单元。\n",
    "* 撤销被删除的单元，按 Z。\n",
    "* Y 会将当前活跃的单元变成一个代码单元。\n",
    "* 按住 Shift +上或下箭头可选择多个单元。在多选模式时，按住 Shift + M 可合并你的选择。\n",
    "* 按 F 会弹出「查找和替换」菜单。\n",
    "___\n",
    "\n",
    "### ②.处于编辑模式时（在命令模式时按 Enter 会进入编辑模式），我们会发现下列快捷键很有用：\n",
    "* Ctrl + Home 到达单元起始位置。\n",
    "* Ctrl + S 保存进度。（√）\n",
    "* 如之前提到的，Ctrl + Enter 会运行你的整个单元块。（√）\n",
    "* Alt + Enter 不止会运行你的单元块，还会在下面添加一个新单元。(√)\n",
    "* Ctrl + Shift + F 打开命令面板。\n",
    "\n",
    "\n",
    "\n",
    "## 2.常见的几个模块的使用\n",
    "\n",
    "* datetime \n",
    "* time\n",
    "* help() \n",
    "* [range()函数的使用](https://docs.python.org/3/tutorial/controlflow.html#the-range-function) <font color=pink size=3>**重点**</font> [range源代码](https://docs.python.org/3/library/stdtypes.html#range)\n",
    "* random 模块的使用 <font color=pink size=3>**重点**</font> \n",
    "\n",
    "-----------\n",
    "\n",
    "\n",
    "## 3. if else 循环嵌套的使用 （半√/明白原理，实践有点懵。）\n",
    "\n",
    "* [if教程及案例学习](https://docs.python.org/3/tutorial/controlflow.html#if-statements)\n",
    "* 多层嵌套 \n",
    "\n",
    "```\n",
    "if 条件:\n",
    "      if-语句块\n",
    "   \n",
    "   if 条件:\n",
    "      if-语句块\n",
    "   else:\n",
    "      else-语句块\n",
    "   \n",
    "   if 条件：\n",
    "      if-语句块\n",
    "   elif 条件:\n",
    "      elif-语句块\n",
    "   ...\n",
    "   else:\n",
    "      else-语句块\n",
    "   可以进行嵌套。 不要超过3层， 最多5层\n",
    "```\n",
    "-----------\n",
    "\n",
    "## 4. for 循环 配合 内置函数range()的使用\n",
    "\n",
    "* [for教程及案例学习](https://docs.python.org/3/tutorial/controlflow.html#for-statements)\n",
    "\n",
    "-----------\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ae9e84c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# if else 循环嵌套的使用\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26b43dc7",
   "metadata": {},
   "outputs": [],
   "source": [
    ">>> print sys\n",
    ">>>sys.platform\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a9ff32d",
   "metadata": {},
   "source": [
    "# 二、关于help（）、datetime 、 time、range"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3be1f5bc",
   "metadata": {},
   "source": [
    "<font color=pink size=4>**关于help()**</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad433fa0",
   "metadata": {},
   "outputs": [],
   "source": [
    "help()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3e82b93",
   "metadata": {},
   "source": [
    "<font color=pink size=4>**关于time、datetime**</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f3e6ed10",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2021/09/26 21:52'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "from datetime import datetime\n",
    "time.strftime(\"%Y/%m/%d %H:%M\") # 前面有个单引号是因为没有print起来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9851147b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021/09/26 21:52:39\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "print(time.strftime(\"%Y/%m/%d %H:%M:%S\", time.localtime())) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "328f917b",
   "metadata": {},
   "source": [
    "<font color=pink size=4>**关于range**</font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9e398d1",
   "metadata": {},
   "source": [
    "> range的中文意思是，范围、幅度、或者是在xxx之间变动  \n",
    "> 函数原型：range（start， end， scan):  \n",
    "> 参数含义：start:计数从start开始。默认是从0开始。例如range（5）等价于range（0， 5);  \n",
    "***\n",
    "> end:技术到end结束，但不包括end.例如：range（0， 5） 是[0, 1, 2, 3, 4]没有5  \n",
    "> scan：每次跳跃的间距，默认为1。例如：range（0， 5） 等价于 range(0, 5, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0fa4f48",
   "metadata": {},
   "outputs": [],
   "source": [
    "写一个最常用的for循环\n",
    "\n",
    "for index in range(1,100):\n",
    "    print(\"index:{_index}\".format(_index = index))\n",
    "\n",
    "1\n",
    "2\n",
    "3\n",
    "4\n",
    "5\n",
    "..\n",
    "100\n",
    "\n",
    "这里的range就是从1 变动到 100\n",
    "\n",
    "另外，range也可以动态创建一个元素列表\n",
    "\n",
    "list = [range(0,10)]\n",
    "print(list)\n",
    "\n",
    "0\n",
    "1\n",
    "2\n",
    "3\n",
    "...\n",
    "9\n",
    "\n",
    "这里 range执行了10次，从0 到 9\n",
    "\n",
    "\n",
    "再来看一个range的跳跃\n",
    "\n",
    "for index in range(0,10,2):\n",
    "    print(\"index:{_index}\".format(_index = index))\n",
    "0\n",
    "2\n",
    "4\n",
    "6\n",
    "8\n",
    "\n",
    "根据输出结果可以看到，这里每隔1次生成一个数字\n",
    "当然，这里默认是1，表示没有间隔"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b000137f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课本p4-p16讨论的代码\n",
    "from datetime import datetime\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute # datetime.today().minute 当前的时间的分钟\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c66539d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 超哥笔记里的代码\n",
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "# range(5) 将和for循环一起实现 for循环子代码执行的次数（5）\n",
    "for i in range(5):\n",
    "    # right_this_second 当前时间点的秒数\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(\"该时间为秒为单位的奇数时间.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    # wait_time 等待的时间\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time)\n",
    "\n",
    "# 该时间为秒为单位的奇数时间.\n",
    "# Not an odd second.\n",
    "# 该时间为秒为单位的奇数时间.\n",
    "# Not an odd second.\n",
    "# 该时间为秒为单位的奇数时间."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "948b2f88",
   "metadata": {},
   "source": [
    "# 三.关于课本项目练习："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c291aa00",
   "metadata": {},
   "outputs": [],
   "source": [
    "today = input(\"weekday:\") #input是一个输入栏，输入下面其中代码就有相应的结果。\n",
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    condition = input(\"mood:\")\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d3e1c16",
   "metadata": {},
   "source": [
    "<font color=pink size=4>**关于用户输入**</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f11775d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "username:254\n",
      "password:245、\n",
      "254 245、\n"
     ]
    }
   ],
   "source": [
    "# F-01 初始 input\n",
    "\n",
    "username = input(\"username:\")\n",
    "password = input(\"password:\")\n",
    "\n",
    "print(username,password)\n",
    "\n",
    "# username:111\n",
    "# password:11111\n",
    "# 111 11111  （最终输出）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "661a74f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# F-02 字符串拼接+打印：\n",
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "info = '''----- INFO OF ''' + name +'''------''' + '''\n",
    "age:''' + age+'''\n",
    "job:''' + job +'''\n",
    "salary:'''+salary\n",
    "\n",
    "print(info)\n",
    "\n",
    "# name:111\n",
    "# age:111\n",
    "# job:1111\n",
    "# salary:11111\n",
    "# ----- INFO OF 111------\n",
    "# age:111\n",
    "# job:1111\n",
    "# salary:11111\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1e49cb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# F-03 %s 使用（是不是很麻烦？有没有更简单的方式将打印内容？接下来我们来学习 %s 占位符。）\n",
    "\n",
    "# %s代表 string\n",
    "\n",
    "# %d代表 number\n",
    "\n",
    "# %f代表 float\n",
    "\n",
    "# F-03 %s 使用（是不是很麻烦？有没有更简单的方式将打印内容？接下来我们来学习 %s 占位符。）\n",
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "info = '''-------INFO OF %s -------\n",
    "Name:%s\n",
    "Age:%s\n",
    "Job:%s\n",
    "Salary:%s\n",
    "'''% (name,name,age,job,salary)\n",
    "\n",
    "print(info)\n",
    "\n",
    "# name:1\n",
    "# age:1\n",
    "# job:1\n",
    "# salary:1\n",
    "# -------INFO OF 1 -------\n",
    "# Name:1\n",
    "# Age:1\n",
    "# Job:1\n",
    "# Salary:1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9208a55",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "307.2px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
